import request from '@/utils/request'
import request_file from '@/utils/request_file'
// 按派工查询
export function getLeft(data) {
	return request({
		url: '/plan/v9/bc/bench/selectLeft',
		method: 'post',
		data: data
	})
}

//放开限制全体查询
export function btnSelectLeftListByMo(mo) {
	return request({
		url: '/plan/v9/bc/bench/btnSelectLeftListByMo',
		method: 'get',
		params: {
			mo,
		}
	})
}

//点击工单
export function getJobByJobId(jobId) {
	return request({
		url: '/plan/v9/bc/bench/getJobByJobId',
		method: 'get',
		params: {
			jobId,
		}
	})
}

//同步按钮
export function createKzFile(DrawingNo, DrawingNoRev, ItemCode) {
	return request_file({
		url: '/api/soa/downProcessDocuments',
		method: 'get',
		headers: {
			isToken: false
		},
		params: {
			DrawingNo: DrawingNo,
			DrawingNoRev: DrawingNoRev,
			ItemCode: ItemCode
		}
	})
}
//报工记录
export function listByJobId(jobId) {
	return request({
		url: '/development/v9/reportRecord/listByJobId',
		method: 'get',
		params: {
			jobId: jobId
		}
	})
}
//反馈记录
export function listByParam(data) {
	return request({
		url: '/development/v9/SceneAbnormalFeedback/listByParam',
		method: 'post',
		data: data
	})
}
//反馈记录 weburl
export function createUrl(partyCode, id) {
	return request({
		url: '/development/v9/SceneAbnormalFeedback/createUrl',
		method: 'get',
		params: {
			partyCode: partyCode,
			id: id
		}
	})
}
//异常反馈加载radio数据
export function configListByParam(productionType, pid, processLevel) {
	return request({
		url: '/development/v9/sceneAbnormalConfig/listByParam',
		method: 'get',
		params: {
			productionType: productionType,
			pid: pid,
			processLevel: processLevel
		}
	})
}
//下拉人员信息加载
export function partyListByParam(configId) {
	return request({
		url: '/development/v9/sceneAbnormalParty/listByParam',
		method: 'get',
		params: {
			configId: configId
		}
	})
}
// 提交異常反饋
export function createProcess(data) {
	return request({
		url: '/development/v9/SceneAbnormalFeedback/createProcess',
		method: 'post',
		data: data
	})
}
//刷新refreshToken
export function refreshToken(configId) {
	return request({
		url: '/system/v9/token/refreshToken',
		method: 'get',
	})
}

//获取getWebsocket地址
export function getWebsocketUrl() {
	return request({
		url: '/plan/v9/bc/bench/getWebsocketUrl',
		method: 'get',
	})
}

//现场接收
export function confirmReviceTask(data, userCode) {
	return request({
		url: '/development/v9/machineScene/confirmReviceTask',
		method: 'post',
		data: data,
		params: {
			userCode
		}
	})
}

//手动开工
export function startWork(data) {
	return request({
		url: '/plan/v9/bc/bench/startWork',
		method: 'post',
		data: data
	})
}

//手动完工
export function endWork(data) {
	return request({
		url: '/plan/v9/bc/bench/endWork',
		method: 'post',
		data: data
	})
}

//转移下序
export function transfer(data) {
	return request({
		url: '/plan/v9/surface/processPlan/transfer',
		method: 'post',
		data: data
	})
}

//获取文件
// export function getViewPDF( DocNo, Rev, ProNo, ItemCode, OrgCode) {
// 	return request_file({
// 		url: '/api/SOA/ViewPDF',
// 		method: 'get',
// 		headers: {
// 			isToken: false
// 		},
// 		params: {
// 			DocNo: DocNo,   // 图号
// 			Rev: Rev,       // 版本号
// 			ProNo: ProNo,   // 工单号
// 			ItemCode: ItemCode,  // 料号
// 			OrgCode: OrgCode,  // 组织
// 		}
// 	})
// }

export const getViewPDF = ( DocNo, Rev, ProNo, ItemCode, OrgCode)  => {
	return request({
		url: 'http://192.168.10.3:8008/api/SOA/ViewPDF',
		method: 'get',
		params: {
			DocNo: DocNo,   
			Rev: Rev,       
			ProNo: ProNo,  
			ItemCode: ItemCode, 
			OrgCode: OrgCode, 
		}
	})
}

String.prototype.myReplace = function(f, e) { //吧f替换成e
	var reg = new RegExp(f, "g"); //创建正则RegExp对象   
	return this.replace(reg, e);
}

// 工艺文件
export function findOrgCode() {
	return request({
		url: '/development/v9/machineScene/findOrgCode',
		method: 'get',
	})
}

// AR 指导
export const checkArGuid = (mCode, processOrder) => {
	return request({
		url: '/plan/v9/bc/bench/checkArGuid',
		method: 'get',
		params: {
			mCode,
			processOrder
		}
	})
}

// 读取异常
export const bomFeedbackInfoItemSaveAllItemPolish = (param) => {
	return request({
		url: '/quality/v9/BomFeedbackInfoItem/saveAllItemPolish',
		method: 'post',
		data: param
	})
}

/**
 * 日期格式化
 */
export function dateFormat(date, format) {
	format = format || 'yyyy-MM-dd hh:mm:ss';
	if (date !== 'Invalid Date') {
		let o = {
			"M+": date.getMonth() + 1, //month
			"d+": date.getDate(), //day
			"h+": date.getHours(), //hour
			"m+": date.getMinutes(), //minute
			"s+": date.getSeconds(), //second
			"q+": Math.floor((date.getMonth() + 3) / 3), //quarter
			"S": date.getMilliseconds() //millisecond
		}
		if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
			(date.getFullYear() + "").substr(4 - RegExp.$1.length));
		for (let k in o)
			if (new RegExp("(" + k + ")").test(format))
				format = format.replace(RegExp.$1,
					RegExp.$1.length === 1 ? o[k] :
					("00" + o[k]).substr(("" + o[k]).length));
		return format;
	}
	return '';

}